<template>

    <div style="background:#f8f8f9">
        <div v-if="show" style="border-bottom: 1px solid #f5f7f9;text-align:center;">
        </div>
        <div v-else>
        <div style="border-bottom:1px solid #999;text-align:center;" >
            <h3>{{publicity.Title}}</h3>
            <p style="padding:15px 0">
                <span style="margin-right:30px;">所属行业：{{publicity.Industry}}</span>
                <span>发布时间：<!--2018-9-20-->{{publicity.PublicityTime|formatDate1}}</span>
            </p>
        </div>
        <div style="padding:30px;border-bottom:1px solid #999">
          <div v-html="publicity.Content"></div>
          <div v-for="(item,index) in fileList" :key="index" style="margin:10px 0">
            <!-- <Icon type="md-help" size='20'/> -->
            <a :href="item.url" :download='item.name'>{{item.name}}</a>
          </div>
        </div>
            <div style="padding:30px;">
                <p @click="getLastNext(last.Id)" class="p-hover" >上一篇：{{!last?'没有上一篇啦':last.Title}}</p>
                <p @click="getLastNext(next.Id)" class="p-hover">下一篇：{{!next?'没有下一篇啦':next.Title}}</p>
            </div>
        </div>
    </div>
</template>

<script>
    import {formatDate} from '../libs/tools.js';
    export default {
        data() {
            return {
                show:true,
                publicity:{
                    PublicityTime:'2018-09-00 00:00:00',
                    Title:'',
                    Industry:'',
                },
                last:{},
                next:{},
                isHot:'',
                isIndex:'',
                fileList: []
            }
        },
        filters:{
            formatDate1(time){
                let date = new Date(time);
                return formatDate(date,'yyyy-MM-dd');
            }
        },
        computed: {
            id() {
                if(!this.$store.state.hotId) {
                    var storage=window.localStorage;
                    return storage.getItem("projectId");
                }else{
                    return this.$store.state.hotId;
                }
            }
        },
        mounted() {
            this.getLastNext();
        },
        methods: {
            getLastNext(value){
                this.show = true;
                this.$post('/publicity/getLastNext',
                    {
                        Id:!value?this.id.slice(0,36):value,
                        IsHot:!this.isHot?this.id.slice(36):this.isHot,
                        IsIndex:!this.isIndex?this.id.slice(36):this.isIndex,
                    }
                )
                    .then( (res) => {
                        this.fileList = [] //先清空下载列表
                        if(res._STATUS == 1) {
                            switch (res.this.ProjectType) {
                                case '0':
                                    this.$store.commit('changeState',res.this.ProjectType)
                                    break;
                                case '1':
                                    this.$store.commit('changeState',res.this.ProjectType)
                                    break;
                                case '2':
                                    this.$store.commit('changeState',res.this.ProjectType)
                                    break;
                                case '3':
                                    this.$store.commit('changeState',res.this.ProjectType)
                                    break;
                                case '4':
                                    this.$store.commit('changeState',res.this.ProjectType)
                                    break;
                                default:
                                    break;
                            }
                            this.publicity = res.this;
                            this.last = res.last;
                            this.next = res.next;
                            this.isHot = res.IsHot;
                            this.isIndex = res.IsIndex;
                            this.show = false;
                        /* this.$store.commit('toggleHotId',res.this.Id+this.isHot?this.isHot:this.isIndex);*/
                            scrollTo(0,0);
                            // 获取下载文件列表
                            this.$post('publicity.findByEnclosure',{Id: res.this.Id}).then(response=>{
                                if(response._STATUS==1) {
                                    // 上传文件列表
                                    var PublicityEnclosure = response.PublicityEnclosure
                                    if(PublicityEnclosure.length>0) {
                                        PublicityEnclosure = PublicityEnclosure.map(el=>{
                                            var arr = el.Name.split('.')
                                            arr[0] = decodeURIComponent(arr[0])
                                            el.Name = arr.join('.')
                                            this.fileList.push({
                                                name:el.Name,
                                                url: el.Enclosure,
                                                id: el.Id
                                            })
                                        })
                                    }
                                }
                            })
                        }
                    })
                    .catch( (error) => {
                        console.log(error);
                    });
            },
        },
        created() {

        },
        watch: {
           'id'(){
               this.getLastNext();
           },
        }
    }
</script>

<style>
    .p-hover:hover{color:blue;cursor:pointer}
</style>
